package org.sample.web;

import org.sample.entity.Log;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 报警阻塞队列
 * Created by Alan on 2016/10/1.
 */
public enum AlarmMessageQueue {

    Instance;

    //队列大小
    public static final int QUEUE_MAX_SIZE = 1000;

    //阻塞队列
    private BlockingQueue<Log> blockingQueue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE);

    /**
     * 消息入队
     */
    public boolean push(Log log) {
        return this.blockingQueue.offer(log);
    }

    /**
     * 消息出队
     */
    public Log poll() {
        Log result = null;
        try {
            result = this.blockingQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 获取队列大小
     */
    public int size() {
        return this.blockingQueue.size();
    }
}